// components/ui/my-modal.tsx

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from '@/components/ui/dialog';
import { ReactNode } from 'react';

interface MyModalProps {
  trigger: ReactNode;      // 触发按钮
  title?: string;          // 标题
  description?: string;    // 副标题
  children: ReactNode;     // 内容
  open?: boolean;          // 受控模式
  onOpenChange?: (open: boolean) => void;
}

export default function MyModal({
  trigger,
  title,
  description,
  children,
  open,
  onOpenChange,
}: MyModalProps) {
  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogTrigger asChild>{trigger}</DialogTrigger>
      <DialogContent>
        {title && (
          <DialogHeader>
            <DialogTitle>{title}</DialogTitle>
            {description && (
              <DialogDescription>{description}</DialogDescription>
            )}
          </DialogHeader>
        )}
        {children}
      </DialogContent>
    </Dialog>
  );
}